package com.bluefish.bltuan.action.email;

import org.apache.struts2.rest.DefaultHttpHeaders;
import org.apache.struts2.rest.HttpHeaders;

import com.bluefish.bltuan.action.AbstractAction;
import com.bluefish.bltuan.service.SubscriberService;
import com.bluefish.bltuan.tools.FormatUtils;

public class UnsubscribeAction extends AbstractAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = -8373918771996317637L;

	private SubscriberService subscriberService;
	
	private String email;
	
	@Override
	public HttpHeaders create() {
		if(this.email != null && FormatUtils.isEmail(this.email)){
			boolean success = this.subscriberService.unSubscribe(this.email);
			if(success)
				return new DefaultHttpHeaders(CREATE).disableCaching();
			else
				addFlashMessage(getText("This email address is not in the subsciber list!"));
		}else{
			addFlashMessage(getText("error email format input,please check and try again!"));
		}
		redirect();
		return null;
	}

	@Override
	public String destroy() {
		return null;
	}

	@Override
	public String edit() {
		return null;
	}

	@Override
	public HttpHeaders editNew() {
		return null;
	}

	@Override
	public HttpHeaders index() {
		return new DefaultHttpHeaders(INDEX).disableCaching();
	}

	@Override
	public HttpHeaders show() {
		return null;
	}

	@Override
	public String update() {
		return null;
	}
	
	public void setSubscriberService(SubscriberService subscriberService) {
		this.subscriberService = subscriberService;
	}
	
	public void setEmail(String email) {
		this.email = email;
	}

}
